package action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections4.map.HashedMap;

import com.google.gson.Gson;

import pojo.AllKnow;
import pojo.BaseDataPojo;
import pojo.Message;
import service.AllKnowService;
import service.MessageService;
import serviceImpl.AllKnowServiceImpl;
import serviceImpl.MessageServiceImpl;


@WebServlet("/AllKnowServlet")
public class AllKnowServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public AllKnowServlet() {
        super();
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {	
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String mark = request.getParameter("mark");
		switch(mark) {
		
		case "getAllKnowDetails":   // 获取考研全知道细节内容
			getAllKnowDetails(request,response);
			break;
		}
	}


	private void getAllKnowDetails(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		String akid = request.getParameter("akid");
		//System.out.println("akid:"+akid);
		AllKnowService ak = new AllKnowServiceImpl();
		AllKnow allKnow = new AllKnow();
		allKnow = ak.getAllKnowDetails(akid);
		Map<String,AllKnow> map = new HashedMap<>();
		map.put("allKnow",allKnow);
		//System.out.println("allKnow:"+allKnow);
		if(allKnow!=null) {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					AllKnow>>("根据akid获取单个AllKnow成功", true, map)));
		}else {
			out.print(new Gson().toJson(new BaseDataPojo<Map<String, 
					AllKnow>>("根据akid获取单个AllKnow为空或失败", false, map)));
		}
	}

}
